package org.jspresso.framework.application.frontend.action;

import java.util.Map;

import org.jspresso.framework.action.IActionHandler;
import org.jspresso.framework.application.backend.persistence.hibernate.HibernateBackendController;
import org.jspresso.framework.model.component.IComponent;
import org.jspresso.model.TestEntity;
import org.jspresso.tester.utils.TestEntitySerializer;

public class LoadEntityFromTestEntity<E,F,G> extends FrontendAction<E,F,G> {
	@SuppressWarnings("unchecked")
	@Override
	public boolean execute(IActionHandler actionHandler, Map<String, Object> context) {
		TestEntity testEntity = getSelectedModel(context);
		IComponent loadedEntity = TestEntitySerializer.unserializeFromStore(testEntity.getEntityId(), (Class<? extends IComponent>)(testEntity.getClazz()), null, (HibernateBackendController) getBackendController(context));
		if(loadedEntity != null) {
			setActionParameter(loadedEntity, context);
			return super.execute(actionHandler, context);
		}
		return false;
	}
}
